package com.xes.rabbitmq.producte.handler.simple;

import com.alibaba.fastjson.JSON;
import com.xes.rabbitmq.core.domain.tables.pojos.TbStudent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SimpleStudentSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(TbStudent student) {
        log.info("消息发送内容：{}", JSON.toJSONString(student));
        CorrelationData correlationData = new CorrelationData(student.getId());
        rabbitTemplate.convertAndSend(
                "student-exchange",
                "student-#",
                student,
                correlationData
        );
    }
}
